using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace Tron.Animations
{
    public abstract class SteppedAnimation : Animation
    {
        int stepCount;
        double stepDuration;

        float progressBetweenSteps;

        double nextStepProgress = 0;
        int nextStepNumber = 0;

        public double StepDuration
        {
            get
            {
                return stepDuration;
            }
        }

        public int StepCount
        {
            get
            {
                return stepCount;
            }
        }

        public SteppedAnimation(int stepCount, double stepDuration, double timeBetweenSteps)
            : base(stepDuration + timeBetweenSteps * (stepCount - 1))
        {
            this.stepCount = stepCount;
            this.stepDuration = stepDuration;
            this.progressBetweenSteps = (float)((1 - StepDuration / Duration) / (StepCount - 1));
        }

        protected virtual void Step(int stepNumber) {}

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            while (nextStepProgress <= Progress && nextStepNumber < stepCount)
            {
                Step(nextStepNumber);
                nextStepProgress += progressBetweenSteps;
                nextStepNumber++;
            }
        }
    }
}
